#-*-coding:UTF-8 -*-
'''
Created on 2013-6-4

@author: Administrator
'''
import os, sys
from stat import *


BIG_FILE_THREHOLD = 10000000L;
dict1 = {}
dict2 = {}

def treewalk(path):
    ''' '''
    try :
        for i in os.listdir(path):
            mode = os.stat(path + '/' + i).st_mode
            
            if S_ISDIR(mode) != True:
                filename = path + "/" + i
                filesize = os.stat(filename).st_size
                if filesize > BIG_FILE_THREHOLD:
                    if filesize in dict1:
                        dict2[filename] = filesize
                        dict2[dict1[filesize]] = filesize
                    else:
                        dict1[filesize] = filename
            else:
                treewalk(path + '/' + i)
    except WindowsError:
        pass

def printdict(finaldict):
    """ """
    file = open(r'F:\workspace\mypython\bigFile.txt','w')  # @ReservedAssignment
    for i_size in finaldict.values():
        print i_size
        file.write(str(i_size))
        file.write(os.linesep)
        for j_name in finaldict.keys():
            if finaldict[j_name] == i_size:
                print j_name.decode('GBK').encode('UTF-8')
                file.write(j_name.decode('GBK').encode('UTF-8'))
                file.write(os.linesep)
        print '\n'
    file.flush()
    file.close()
if __name__ == "__main__":
    treewalk(r"F:\workspace\wutianyi-study")
    printdict(dict2)
                        
            